﻿public class MyQueue
{
    Stack<int> head ;//输出使用
    Stack<int> nail;//输入使用

    public MyQueue()
    {
        head = new Stack<int>();//输出使用
        nail = new Stack<int>();//输入使用
    }

    public void Push(int x)//进队尾
    {
    

        nail.Push(x);
    }

    public int Pop()//出对头

    {
        if (head.Count==0)
        {
            In2Out();//空了才去取值，这样不需要转移回来
        }

      


            return head.Pop();
       




    }
    public void In2Out()//输入栈放到输出栈
    {

        while (nail.Count > 0)
        {


            int cur = nail.Pop();
            head.Push(cur);
        }

    }

    public int Peek()
    {
        if (head.Count == 0)
        {
            In2Out();//空了才去取值，这样不需要转移回来
        }


        return head.Peek();
    }

    public bool Empty()
    {
        if(head.Count == 0&& nail.Count == 0)
        {

            return true;
        }
        return false;


    }
}

/**
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue obj = new MyQueue();
 * obj.Push(x);
 * int param_2 = obj.Pop();
 * int param_3 = obj.Peek();
 * bool param_4 = obj.Empty();
 */

class program232
{




    static void Main232(string[] args)
    {
        MyQueue obj = new MyQueue();
        obj.Push(1);
        obj.Push(2);
        int param_3 = obj.Peek();
        Console.WriteLine(param_3);
        int param_2 = obj.Pop();
        Console.WriteLine(param_2);
        
        bool param_4 = obj.Empty();
        Console.WriteLine(param_4);


    }
}